package org.sky.logger.name.support;

import javax.servlet.http.HttpServletRequest;

import org.sky.logger.name.AppName;
import org.sky.logger.util.Util;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

/**
 * web上下文
 * 
 * @author gaofu
 *
 */
public class ContextPathAppName implements AppName {
	private HttpServletRequest request = getRequest();

	/**
	 * 取得HttpRequest的简化函数.
	 */
	public HttpServletRequest getRequest() {
		return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
	}

	public String name() {
		String name = null;
		try {
			name = request.getContextPath();
			if (!Util.isEmpty(name)) {
				name = name.replace("/", "");
			}
		} catch (Throwable e) {
		}
		return name;
	}

}
